/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import entities.Service;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import entities.*;
import java.util.*;
import javax.persistence.*;

/**
 *
 * @author xuanthuy
 */
@Stateless
public class ServiceFacade extends AbstractFacade<Service> {

    @PersistenceContext(unitName = "AlluringDecorsPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ServiceFacade() {
        super(Service.class);
    }

    public List<Service> truyvanAll() {
        try {
            Query q = this.em.createQuery("select sv from Service sv where sv.status = TRUE");
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
    
    public List<Service> truyvan1() {
        try {
            Query q = this.em.createQuery("select sv from Service sv where sv.status = FALSE");
            return q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
    
    public Service checkName(String name){
        try {
            Query q = this.em.createQuery("select sv from Service sv where sv.name=:name");
            q.setParameter("name", name);
            return (Service) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }
}
